﻿/************************************************************************************
* Copyright (c) 2019 All Rights Reserved.
*命名空间：Separate.DAL.MySQL
*文件名： MySqlFunction
*创建人： Liebeskind
*创建时间：2019/6/13 14:52:37
*描述
*=====================================================================
*修改标记
*修改时间：2019/6/13 14:52:37
*修改人：Liebeskind
*描述：认为线上的所有对象都是Package，可能是摞，可能是盘。
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlHelper;
//using Commonality.DAL.WZS_SFCS;
using System.Text.RegularExpressions;

namespace Commonality.DAL.MySQL
{
    public static class MySqlFunction
    {
        public static SqlHelper.MySql MySql;
        public static void InitMySQLFunction()
        {
            MySql = new SqlHelper.MySql();
        }

        public static class PackageOrientation
        {
            //表名
            public static string TabName = "package_orientation";
            //表头
            public static string Usn_key = "usn_key";

            public static string Orientation = "orientation";
            public static string Message = "message";
            public static string Data_time = "data_time";
            #region 新增
            /// <summary>
            /// 增加-异常摞/盘信息
            /// </summary>
            /// <param name="usn">SN</param>
            /// <param name="orientation">流到方向：0.下行；1.异常1；2.异常2；3.异常3</param>
            /// <param name="package_message">异常信息</param>
            public static void PackageOrientation_INSERT(string usn, int orientation, string package_message)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4}) values('{5}',{6},'{7}','{8}')",           TabName,
                                                                                                                            Usn_key, Orientation,Message,Data_time,
                                                                                                                            usn, orientation, package_message, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion

            #region 改
            /// <summary>
            /// 跟新数据
            /// </summary>
            /// <param name="usnKey"></param>
            /// <param name="orientation"></param>
            /// <param name="package_message"></param>
            public static void PackageOrientation_UPDATE(string usnKey, int orientation, string package_message)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}',{3} = '{4}' WHERE {5} = '{6}'", TabName,
                                                                                                                            Orientation, orientation,
                                                                                                                            Message, package_message,
                                                                                                                            Usn_key, usnKey);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion

            #region 查询
            /// <summary>
            /// 查询数据
            /// </summary>
            /// <param name="usnKey"></param>
            /// <param name="orientation"></param>
            /// <param name="package_message"></param>
            public static void PackageOrientation_SELECT(string usnKey,ref int orientation,ref  string package_message)
            {
                string[] dict = new string[2];
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("select {0},{1} from {2} where {3} = '{4}'",           Orientation, Message,
                                                                                                    TabName,
                                                                                                    Usn_key, usnKey);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                orientation = Convert.ToInt16(dict[0]);
                package_message = dict[1];
            }
            #endregion

            #region 删除

            #endregion
        }

        //public static class TrayCellDataList
        //{
        //    //表名
        //    public static string TabName = "traycell_datalist";
        //    //表头
        //    public static string Usn_key_a = "usn_key_a";
        //    public static string Usninfo_a = "usninfo_a";
        //    public static string Bin_a = "bin_a";

        //    public static string Usn_key_b = "usn_key_b";
        //    public static string Usninfo_b = "usninfo_b";
        //    public static string Bin_b = "bin_b";

        //    public static string Eigenvector = "eigenvector";

        //    public static string Data_time = "data_time";
        //    #region 新增
        //    public static void TrayCellDataList_INSERT(ProductCellData cella, ProductCellData cellb)
        //    {
        //        string usn_a = cella.usn;
        //        string usn_b = cellb.usn;

        //        string usninfo_a = string.Join("|", cella.usnInfo);
        //        string usninfo_b = string.Join("|", cellb.usnInfo);

        //        string bin_a = string.Join("|", cella.bin);
        //        string bin_b = string.Join("|", cellb.bin);

        //        try
        //        {
        //            string errorMessage = "";
        //            string time = DateTime.Now.ToString("HH:mm:ss");
        //            string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7}) values('{8}','{9}','{10}','{11}','{12}','{13}','{14}')",     
        //                                                                                                TabName,                                                                                                                                       
        //                                                                                                Usn_key_a, Usninfo_a, Bin_a, Usn_key_b, Usninfo_b, Bin_b, Data_time,
        //                                                                                                usn_a, usninfo_a, bin_a, usn_b, usninfo_b, bin_b,time);
        //            MySql.InsertData(sql, out errorMessage);
        //            if (errorMessage != "")
        //            {

        //            }
        //        }
        //        catch (Exception ex)
        //        {

        //        }
        //    }
        //    #endregion

        //    #region 改
        //    /// <summary>
        //    /// 更新tray的类型特征向量
        //    /// </summary>
        //    /// <param name="usnKeya"></param>
        //    /// <param name="usnKeyb"></param>
        //    /// <param name="eigenvector"></param>
        //    public static void TrayCellDataList_Eigenvector_UPDATE(string usnKeya, string usnKeyb, ref string eigenvector)
        //    {
        //        try
        //        {
        //            string errorMessage = "";
        //            string time = DateTime.Now.ToString("HH:mm:ss");
        //            string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}' or {5} = '{6}'",               TabName,
        //                                                                                                                    Eigenvector, eigenvector,
        //                                                                                                                    Usn_key_a, usnKeya,
        //                                                                                                                    Usn_key_b, usnKeyb);
        //            MySql.UpdateData(sql, out errorMessage);
        //            if (errorMessage != "")
        //            {

        //            }
        //        }
        //        catch (Exception ex)
        //        {

        //        }
        //    }
        //    #endregion

        //    #region 查询
        //    public static void TrayCellDataList_SELECT(string usnKeya, string usnKeyb,ref ProductCellData cella)
        //    {
        //        string[] dict = new string[2];
        //        try
        //        {
        //            string errorMessage = "";
        //            string time = DateTime.Now.ToString("HH:mm:ss");
        //            string sql = string.Format("select {0},{1} from {2} where {3} = '{4}' or {5} = '{6}'", Usninfo_a, Bin_a,
        //                                                                                            TabName,
        //                                                                                            Usn_key_a, usnKeya, 
        //                                                                                            Usn_key_b, usnKeyb);

        //            DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
        //            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //            {
        //                for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
        //                {
        //                    dict[j] = ds.Tables[0].Rows[i][j].ToString();
        //                }
        //            }
        //            if (errorMessage != "")
        //            {

        //            }
        //        }
        //        catch (Exception ex)
        //        {

        //        }
        //        cella.usnInfo = dict[0].Split(new char[] { '|' }); ;
        //        cella.bin = dict[1].Split(new char[] { '|' }); ;
        //    }
        //    public static void TrayCellDataList_SN_SELECT(string usnKeya,ref string usnb)
        //    {
        //        string[] dict = new string[1];
        //        try
        //        {
        //            string errorMessage = "";
        //            string time = DateTime.Now.ToString("HH:mm:ss");
        //            string sql = string.Format("select {0} from {1} where {2} = '{3}'",             Usn_key_b,
        //                                                                                            TabName,
        //                                                                                            Usn_key_a, usnKeya);

        //            DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
        //            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //            {
        //                for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
        //                {
        //                    dict[j] = ds.Tables[0].Rows[i][j].ToString();
        //                }
        //            }
        //            if (errorMessage != "")
        //            {

        //            }
        //        }
        //        catch (Exception ex)
        //        {

        //        }
        //        usnb = dict[0];
        //    }
        //    /// <summary>
        //    /// 查询tray的类型特征向量
        //    /// </summary>
        //    /// <param name="usnKeya"></param>
        //    /// <param name="usnKeyb"></param>
        //    /// <param name="eigenvector"></param>
        //    public static void TrayCellDataList__Eigenvector_SELECT(string usnKeya, string usnKeyb, ref string eigenvector)
        //    {
        //        string[] dict = new string[1];
        //        try
        //        {
        //            string errorMessage = "";
        //            string time = DateTime.Now.ToString("HH:mm:ss");
        //            string sql = string.Format("select {0} from {1} where {2} = '{3}' or {4} = '{5}'", Eigenvector,
        //                                                                                            TabName,
        //                                                                                            Usn_key_a, usnKeya,
        //                                                                                            Usn_key_b, usnKeyb);

        //            DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
        //            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //            {
        //                for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
        //                {
        //                    dict[j] = ds.Tables[0].Rows[i][j].ToString();
        //                }
        //            }
        //            if (errorMessage != "")
        //            {

        //            }
        //        }
        //        catch (Exception ex)
        //        {

        //        }
        //        eigenvector = dict[0];
        //    }
        //    #endregion

        //    #region 删除

        //    #endregion
        //}

        public static class PacketData
        {
            //表名
            public static string TabName = "packet_data";
            //表头
            public static string Usn1 = "usn1";
            public static string Usn2 = "usn2";
            public static string Usn3 = "usn3";
            public static string Usn4 = "usn4";
            public static string Usn5 = "usn5";
            public static string Usn6 = "usn6";
            public static string Usn7 = "usn7";
            public static string Usn8 = "usn8";
            public static string Usn9 = "usn9";
            public static string Usn10 = "usn10";

            public static string Usn11 = "usn11";
            public static string Usn12 = "usn12";
            public static string Usn13 = "usn13";
            public static string Usn14 = "usn14";
            public static string Usn15 = "usn15";
            public static string Usn16 = "usn16";
            public static string Usn17 = "usn17";
            public static string Usn18 = "usn18";
            public static string Usn19 = "usn19";
            public static string Usn20 = "usn20";



            public static string Usn_list_count = "usn_list_count";

            public static string Data_time = "data_time";
            #region 新增
            public static void PacketData_INSERT(List<string> usnList)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}, {21},{22}) values ('{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}')",
                    TabName,
                    Usn1, Usn2, Usn3, Usn4, Usn5, Usn6, Usn7, Usn8, Usn9, Usn10,
                    Usn11, Usn12, Usn13, Usn14, Usn15, Usn16, Usn17, Usn18, Usn19, Usn20, Usn_list_count, Data_time,
                    usnList[0], usnList[1], usnList[2], usnList[3], usnList[4], usnList[5], usnList[6], usnList[7], usnList[8], usnList[9], usnList[10],
                    usnList[11], usnList[12], usnList[13], usnList[14], usnList[15], usnList[16], usnList[17], usnList[18], usnList[19], usnList.Count, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                    
                }

            }
            #endregion
            #region 删除

            #endregion
        }

        public static class AttentionPnData
        {
            //表名
            public static string TabName = "attention_pn_data";

            //表头
            public static string Pn = "pn";
            public static string Mo = "mo";
            public static string Project = "project";
            public static string Birthtime = "birthtime";

            public static string Data_time = "data_time";

            #region 新增
            public static void AttentionPnData_INSERT(string pn,string mo,string project,string birthtime)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5})values('{6}','{7}','{8}','{9}','{10}')", 
                                                                                                                        TabName, 
                                                                                                                        Pn, Mo, Project, Birthtime,Data_time,
                                                                                                                        pn, mo, project, birthtime, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
            #region 查询
            /// <summary>
            /// 加载关注的PN集合
            /// </summary>
            /// <param name="pnData"></param>
            public static void AttentionPnData_SELECT(ref List<string> pnData)
            {
                pnData = new List<string>();
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("select {0} from {1}", Pn, TabName);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            pnData.Add(ds.Tables[0].Rows[i][j].ToString());
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            /// <summary>
            /// 查询此PN的总规划量(忽视MO的分别)
            /// </summary>
            /// <param name="pn"></param>
            /// <param name="project"></param>
            public static void AttentionPnData_Project_SELECT(string pn,ref int project)
            {
                List<string> ProjectList = new List<string>();
                project = 0;
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("select {0} from {1} WHERE {2} = '{3}'", Project, TabName, Pn, pn);
                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            ProjectList.Add(ds.Tables[0].Rows[i][j].ToString());
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                foreach (var item in ProjectList)
                {
                    if (Regex.IsMatch(item, @"^[+-]?\d*$") && item != "")
                    {
                        project = project + Convert.ToInt16(item.ToString());
                    }
                }
            }
            #endregion
            #region 改

            #endregion
            #region 删除
            /// <summary>
            /// 删除过时的PN
            /// </summary>
            /// <param name="pn"></param>
            public static void AttentionPnData_Pn_DELETE(string pn)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("DELETE FROM {0} WHERE {1} = '{2}';",
                    TabName,
                    Pn, pn);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
        }

        public static class Check_PacketData
        {
            public static void Packet_Data_Check(string usnkey, ref string[]data)
            {
                string[] ret = new string[21];
                try
                {
                    string errormessage;
                    string sql = string.Format("select usn1,usn2,usn3,usn4,usn5,usn6,usn7,usn8,usn9,usn10,usn11,usn12,usn13,usn14,usn15,usn16,usn17,usn18,usn19,usn20,usn_list_count from packet_data where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}", usnkey);
                    DataSet ds = MySql.runSQL_getDataset(sql, out errormessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            ret[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    
                }
                catch (Exception ex)
                {

                }
                data = ret;
            }
        }

        public static class DELETE_PacketData
        {
            public static void Packet_Data_Delete(string usnkey)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("DELETE FROM packet_data where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}",
                    usnkey);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
        }


        public static class PacketData_P
        {
            //表名
            public static string TabName = "packet_data_p";
            //表头
            public static string Usn1 = "usn1";
            public static string Usn2 = "usn2";
            public static string Usn3 = "usn3";
            public static string Usn4 = "usn4";
            public static string Usn5 = "usn5";
            public static string Usn6 = "usn6";
            public static string Usn7 = "usn7";
            public static string Usn8 = "usn8";
            public static string Usn9 = "usn9";
            public static string Usn10 = "usn10";

            public static string Usn11 = "usn11";
            public static string Usn12 = "usn12";
            public static string Usn13 = "usn13";
            public static string Usn14 = "usn14";
            public static string Usn15 = "usn15";
            public static string Usn16 = "usn16";
            public static string Usn17 = "usn17";
            public static string Usn18 = "usn18";
            public static string Usn19 = "usn19";
            public static string Usn20 = "usn20";



            public static string Usn_list_count = "usn_list_count";

            public static string Data_time = "data_time";
            #region 新增
            public static void PacketData_INSERT_P(List<string> usnList)
            {
                try
                {
                    List<string> temp = new List<string>();
                    //temp = usnList;
                    usnList.ForEach(i => temp.Add(i));
                    for (int i = 0; i < 20; i++)
                    {
                        temp.Remove("");
                    }
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}, {21},{22}) values ('{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}')",
                    TabName,
                    Usn1, Usn2, Usn3, Usn4, Usn5, Usn6, Usn7, Usn8, Usn9, Usn10,
                    Usn11, Usn12, Usn13, Usn14, Usn15, Usn16, Usn17, Usn18, Usn19, Usn20, Usn_list_count, Data_time,
                    usnList[0], usnList[1], usnList[2], usnList[3], usnList[4], usnList[5], usnList[6], usnList[7], usnList[8], usnList[9], usnList[10],
                    usnList[11], usnList[12], usnList[13], usnList[14], usnList[15], usnList[16], usnList[17], usnList[18], usnList[19], temp.Count, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {


                }

            }
            #endregion

            #region 查询
            public static void Packet_Data_Check_P(string usnkey, ref string[] data)
            {
                string[] ret = new string[21];
                try
                {
                    string errormessage;
                    string sql = string.Format("select usn1,usn2,usn3,usn4,usn5,usn6,usn7,usn8,usn9,usn10,usn11,usn12,usn13,usn14,usn15,usn16,usn17,usn18,usn19,usn20,usn_list_count from packet_data_p where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}", usnkey);
                    DataSet ds = MySql.runSQL_getDataset(sql, out errormessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            ret[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }

                }
                catch (Exception ex)
                {

                }
                data = ret;
            }
            #endregion

            #region 删除
            public static void Packet_Data_Delete_P(string usnkey)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("DELETE FROM packet_data_p where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}",
                    usnkey);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            #endregion
        }



        public static class Check_Label
        {
            //表名
            public static string TabName = "check_label";
            //表头
            public static string Usn1 = "usn1";
            public static string Usn2 = "usn2";
            public static string Usn3 = "usn3";
            public static string Usn4 = "usn4";
            public static string Usn5 = "usn5";
            public static string Usn6 = "usn6";
            public static string Usn7 = "usn7";
            public static string Usn8 = "usn8";
            public static string Usn9 = "usn9";
            public static string Usn10 = "usn10";

            public static string Usn11 = "usn11";
            public static string Usn12 = "usn12";
            public static string Usn13 = "usn13";
            public static string Usn14 = "usn14";
            public static string Usn15 = "usn15";
            public static string Usn16 = "usn16";
            public static string Usn17 = "usn17";
            public static string Usn18 = "usn18";
            public static string Usn19 = "usn19";
            public static string Usn20 = "usn20";



            public static string Usn_list_count = "usn_list_count";

            public static string Data_time = "data_time";
            #region 新增
            public static void Label_INSERT(List<string> usnList)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}, {21},{22}) values ('{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}')",
                    TabName,
                    Usn1, Usn2, Usn3, Usn4, Usn5, Usn6, Usn7, Usn8, Usn9, Usn10,
                    Usn11, Usn12, Usn13, Usn14, Usn15, Usn16, Usn17, Usn18, Usn19, Usn20, Usn_list_count, Data_time,
                    usnList[0], usnList[1], usnList[2], usnList[3], usnList[4], usnList[5], usnList[6], usnList[7], usnList[8], usnList[9], usnList[10],
                    usnList[11], usnList[12], usnList[13], usnList[14], usnList[15], usnList[16], usnList[17], usnList[18], usnList[19], usnList.Count, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {


                }

            }
            #endregion

            #region 查询
            public static void Label_Check(string usnkey, ref string[] data)
            {
                string[] ret = new string[21];
                try
                {
                    string errormessage;
                    string sql = string.Format("select usn1,usn2,usn3,usn4,usn5,usn6,usn7,usn8,usn9,usn10,usn11,usn12,usn13,usn14,usn15,usn16,usn17,usn18,usn19,usn20,usn_list_count from check_label where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}", usnkey);
                    DataSet ds = MySql.runSQL_getDataset(sql, out errormessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            ret[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }

                }
                catch (Exception ex)
                {

                }
                data = ret;
            }
            #endregion

            #region 删除
            public static void Label_Delete(string usnkey)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    string sql = string.Format("DELETE FROM check_label where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}",
                    usnkey);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            #endregion
        }
    }
}
